<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <h:head>
        <title>Test Properties</title>
    </h:head>
    <h:body>
        <h:form id="cache">
            <h2>Cache</h2>
            <p>#{propertyTest.cache.ready}</p>
            <h:commandButton value="Load Cache" action="#{propertyTest.loadCache()}"/>
            <h:commandButton value="Load Cache from file" action="#{propertyTest.loadCacheFromFile()}"/>
            <h:commandButton value="Save Cache" action="#{propertyTest.saveCache()}"/>
            <h:commandButton value="Update props" action="#{propertyTest.updateProperties()}"/>
        </h:form>
        <h:form id="printcache" rendered="#{propertyTest.cache.ready}">
            <h:dataTable  var="p"  value="#{propertyTest.cache.listPropertyValuePairs()}" style="border: 1px black solid">
                <h:column>#{p.property.name} #{p.vpvp.size()}</h:column>
                <h:column>
                    <h:dataTable var="v" value="#{p.listKeys()}" style="border: 1px black solid">
                        <h:column>
                            <h:outputLabel rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValueRange'}" >${p.vpvp[v].min.stringValue}   -    ${p.vpvp[v].max.stringValue} (${p.vpvp[v].count})</h:outputLabel>
                            <h:outputLabel rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValuePair'}"  >${p.vpvp[v].stringValue}  (${p.vpvp[v].count}) </h:outputLabel>
                            <h:inputText rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValues'}" value="${p.vpvp[v].min}" />
                            <h:outputLabel rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValues'}">  - </h:outputLabel>
                            <h:inputText rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValues'}" value="${p.vpvp[v].max}"/>     
                            <h:outputLabel rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValues'}">(${p.vpvp[v].count})</h:outputLabel>
                            
                        </h:column>
                        <h:column>
                            <h:commandButton rendered="#{p.vpvp[v].class.simpleName eq 'PropertyValues'}" action="#{propertyTest.addToFilter(pv)}" />
                            <h:commandButton id="add" value="Add" action="#{propertyTest.addToFilter(p.vpvp[v])}" rendered="#{!propertyTest.pvc.contains(p.vpvp[v])}"/>
                            <h:commandButton id="remove" value="Remove" action="#{propertyTest.removeFromFilter(p.vpvp[v])}"  rendered="#{propertyTest.pvc.contains(p.vpvp[v])}"/>
                        </h:column>
                    </h:dataTable>
                </h:column>
            </h:dataTable>
        </h:form>

        <h:form id="dbdump">
            <h2>ids count</h2>
            <p>#{propertyTest.loadIds()}</p>
            <h2>Categories</h2>
            <h:dataTable var="cat" value="#{propertyTest.listCategories()}">
                <h:column>#{cat.id}-#{cat.name} (#{propertyTest.selectedCategory.id==cat.id?"selected":""})</h:column>
                <h:column>#{cat.children}</h:column>
                <h:column>
                    <h:commandButton value="Select" action="#{propertyTest.selectCategory(cat)}"/>
                </h:column>
            </h:dataTable>
            <h2>Filtered Items</h2>
            <h:dataTable var="fi" value="#{propertyTest.listFilteredItems()}" rendered="#{propertyTest.pvc.size()>0}">
                <h:column>#{fi.name}</h:column>
                <h:column>
                    <h:dataTable var="ip" value="#{fi.properties.values().toArray()}">
                        <h:column>#{ip.property.name}:#{ip.stringvalue}</h:column>
                    </h:dataTable>
                </h:column>
            </h:dataTable>


            <h2>Properties</h2>
            <h:dataTable var="props" value="#{propertyTest.listProperties()}">
                <h:column>#{props.id}-#{props.name}</h:column>
                <h:column>#{props.group.name}</h:column>
                <h:column>#{props.category.name}</h:column>
            </h:dataTable>


            <h2>Groups</h2>
            <h:dataTable var="groups" value="#{propertyTest.listGroups()}">
                <h:column>#{groups.id}-#{groups.name}</h:column>
            </h:dataTable>

            <h2>Values</h2>
            <h:dataTable var="vals" value="#{propertyTest.listValues()}">
                <h:column>#{vals.id}-#{vals.stringvalue}</h:column>
                <h:column>#{vals.property.name}(#{vals.property.category.name})</h:column>
                <h:column>#{vals.item.name}</h:column>


            </h:dataTable>

        </h:form>
        <h:form id="buttons">
            <h:commandButton value="Init" action="#{propertyTest.initDB()}"/>
            <h:commandButton value="Gen From Advs" action="#{propertyTest.genItemsFromAdvs()}"/>
            <h:commandButton value="Gen Data" action="#{propertyTest.genData()}"/>
            <h:commandButton value="Drop" action="#{propertyTest.dropDB()}"/>
        </h:form>
    </h:body>
</html>

